home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11381 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: druid.borland.com!usenet
  2. From: pete@borland.com (Pete Becker)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Fixing stack overflow??
  5. Date: 23 Mar 1996 17:14:20 GMT
  6. Organization: Borland International
  7. Distribution: world
  8. Message-ID: <4j1bhc$dpc@druid.borland.com>
  9. References: <4is899$cg7$1@mhafc.production.compuserve.com> <Pine.A32.3.91.960322143127.23347J-100000@red.weeg.uiowa.edu>
  10. NNTP-Posting-Host: pbecker.borland.com
  11. Mime-Version: 1.0
  12. Content-Type: Text/Plain; charset=ISO-8859-1
  13. X-Newsreader: WinVN 0.99.5
  14.  
  15. In article <Pine.A32.3.91.960322143127.23347J-100000@red.weeg.uiowa.edu>, 
  16. robinson@blue.weeg.uiowa.edu says...
  17. >
  18. >On 21 Mar 1996, Tom wrote:
  19. >
  20. >> I'm using Borland's C compiler and I am getting a stack
  21. >> overflow.  How can I fix this?
  22. >
  23. >1.  Ask for a bigger stack (your compiler docs should have some ideas about 
  24. >how to do that).
  25. >2.  Don't declare enormous arrays as local variables.
  26. >3.  Don't rely on really deep recursion, especially if each invocation of 
  27. >the recursive function declares an enormous array. :-)
  28.  
  29. Let me add that number 1 is rarely the best answer. The key, as ever, is to 
  30. understand why the problem is occurring and then to fix it. I once had to 
  31. overhaul some code that someone else had written. They insisted that they 
  32. needed a 32k stack. The culprit was a really bad implementation of a string 
  33. class they had written that contained a 256 byte char array, combined with 
  34. string operations that created lots of temporary strings along the way. (Yes, 
  35. this was C++ code, but the point is still valid for C) Getting rid of this 
  36. beast and changing to C-style char arrays reduced the stack requirements to 8k.
  37.     -- Pete
  38.  
  39.